#include<iostream>
#include<queue>

using namespace std;

int main(){
	int n,m;
	cin>>n>>m;
	queue<int> q;
	for(int i=1;i<=n;i++){
		q.push(i);
	}
	int i=1;
	while(q.size()>1){
		int t = q.front();
		q.pop();
		if(i==m){
			i=1;
			continue;
		}
		q.push(t);
		i++;
	}
	cout<<q.front();
	return 0;
} 
